package com.zndroid.layertree.ui;

import android.widget.ExpandableListView;

import com.zndroid.layertree.R;
import com.zndroid.layertree.adapter.BaseExpandableAdapter;
import com.zndroid.layertree.model.CData;
import com.zndroid.layertree.model.GData;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class OverViewFragment extends BaseFragment {
    private ExpandableListView expandableListView;
    private List<GData> list = new CopyOnWriteArrayList<>();

    @Override
    protected int layoutId() {
        return R.layout.fragment_overview;
    }

    @Override
    protected void initView() {
        expandableListView = findView(R.id.lt_elv);

        test();
    }

    private void test() {
        GData gData1 = new GData();
        gData1.setName("group 1");
        gData1.setId(1);

        CData cData11 = new CData();
        cData11.setName("child 11");
        cData11.setAge(26);
        cData11.setId(11);

        CData cData12 = new CData();
        cData12.setName("child 12");
        cData12.setAge(28);
        cData12.setId(12);

        List<CData> cData1 = new CopyOnWriteArrayList<>();
        cData1.add(cData11);
        cData1.add(cData12);
        gData1.setSubList(cData1);

/////////////////////////////////
        GData gData2 = new GData();
        gData2.setName("group 2");
        gData2.setId(2);

        CData cData21 = new CData();
        cData21.setName("child 21");
        cData21.setAge(30);
        cData21.setId(21);

        List<CData> cData2 = new CopyOnWriteArrayList<>();
        cData2.add(cData21);
        gData2.setSubList(cData2);
/////////////////////////////////

        GData gData3 = new GData();
        gData3.setName("group 3");
        gData3.setId(3);

        CData cData31 = new CData();
        cData31.setName("child 31");
        cData31.setAge(31);
        cData31.setId(31);
        CData cData32 = new CData();
        cData32.setName("child 32");
        cData32.setAge(305);
        cData32.setId(32);
        CData cData33 = new CData();
        cData33.setName("child 33");
        cData33.setAge(630);
        cData33.setId(33);

        List<CData> cData3 = new CopyOnWriteArrayList<>();
        cData3.add(cData31);
        cData3.add(cData32);
        cData3.add(cData33);
        gData3.setSubList(cData3);
/////////////////////////////////
        list.add(gData1);
        list.add(gData2);
        list.add(gData3);
    }

    @Override
    protected void initData() {
        BaseExpandableAdapter adapter = new BaseExpandableAdapter(getActivity());
        adapter.setNewData(list);

        expandableListView.setAdapter(adapter);
        expandableListView.expandGroup(0);
    }
}
